home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12966 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  107 lines

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Simple Question for the GURUs....
  5. Date: Fri, 22 Mar 1996 13:53:57 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <3152F745.63A@datalytics.com>
  8. References: <1996Mar21.093000.3545@mwk.com>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. hossain@mwk.com wrote:
  16. > *** A stupid question for the GURUS ***
  17. > I have a very simple problem. Should the following code work ?
  18.  
  19. No.  The correct signature for main is:
  20.  
  21. int main(int argc, char **argv, char **env);
  22.  
  23. or, if you prefer:
  24.  
  25. int main(int argc, char *argv[], char *env[]);
  26.  
  27. You can also omit the parameters you don't want (from the 
  28. right), so these are also permissible:
  29.  
  30. int main(int argc, char **argv);
  31. int main(int argc);
  32. int main(void);
  33.  
  34. In each case, however, note that the return type is int.  You 
  35. cannot return a string, though some compilers will allow you to 
  36. declare main as returning void (they will return zero for you).
  37.  
  38. > //File:myapp.c
  39. >         char *main(int argc, char *argv[])
  40. >         {
  41. >            char *temp = (char *)NULL;
  42.  
  43. This was a useless assignment, and the cast is not necessary.
  44.  
  45. >            temp = (char *)malloc(40 * sizeof(char) );
  46.  
  47. Try this instead of using malloc:
  48.  
  49. char *temp = new char[40];
  50.  
  51. >            if ( temp ) strcpy(temp,"Hello World..!!");
  52. >            return(temp);
  53. >         }
  54. > My intent is to have my myapp.exe return to me a string as it should do.
  55.  
  56. The only way to "return" a string is to write it to some IPC, 
  57. like a pipe or socket, or print it to stdout.  The typical way 
  58. to do what you want is to write to stdout:
  59.  
  60. #include <iostream.h>    // cout
  61.  
  62. int main(void)
  63. {
  64.     cout << "Hello World!" << endl;
  65.     return 0;
  66. }
  67.  
  68. > The next part of my problem is I am setting a variable say ALPHA to the string
  69. > coming out of this executable. I am doing this in a PERL script as follows:
  70. > //File: myperl.cmd
  71. > ..............
  72. > ............
  73. >         @GREETINGS = `myapp.exe`;
  74. >         print "Greetings from the Master : @GREETINGS\n";
  75. > ...........
  76. > ..........
  77. > I am doing this in Windows NT environment.The PERL script appear to hang at the
  78. > line @GREETINGS = `myapp.exe`. What is the problem.
  79.  
  80. With the change I gave above, your code should work fine.  The 
  81. Perl code you wrote is waiting to capture the stdout output from 
  82. myapp.exe.  Since there is none, there is nothing to capture.
  83.  
  84. > I will appreciate a response from anyone, who can help solve this apparently
  85. > simple problem. Please e-mail me directly at "hossain@mwk.com".
  86. > Hoping to hear from someone there.
  87. > thanks
  88. > akhtar
  89.  
  90. -- 
  91. Robert Stewart        | My opinions are usually my own.
  92. Datalytics, Inc.    | stew@datalytics.com
  93.